package com.ewhale.feitengguest.ui.user.message.chat;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;
import com.hyphenate.easeui.ui.EaseChatFragment;
import com.hyphenate.easeui.widget.chatrow.EaseCustomChatRowProvider;

import cn.andy.qpopuwindow.QPopuWindow;

import static com.ewhale.feitengguest.ui.user.message.BizChatActivity.rawX;
import static com.ewhale.feitengguest.ui.user.message.BizChatActivity.rawY;


/**
 * PackageName : cn.ewhale.xinnongtong.ui.message.chat
 * Author : Simga
 * Date : 2018/04/24
 * Time : 14:37
 */
public class IMChatFragment extends EaseChatFragment implements EaseChatFragment.EaseChatFragmentHelper{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    protected void setUpView() {
        setChatFragmentHelper(this);
        super.setUpView();
    }

    @Override
    public void onSetMessageAttributes(EMMessage message) {

    }

    @Override
    public void onEnterToChatDetails() {

    }

    @Override
    public void onAvatarClick(String username) {

    }

    @Override
    public void onAvatarLongClick(String username) {

    }

    @Override
    public boolean onMessageBubbleClick(EMMessage message) {
        return false;
    }

    @Override
    public void onMessageBubbleLongClick(EMMessage message,int position,View view) {
        QPopuWindow.getInstance(getContext()).builder
                .bindView(view, position)
                .setPopupItemList(new String[]{"删除", "复制"})
                .setPointers(rawX, rawY)
                .setOnPopuListItemClickListener(new QPopuWindow.OnPopuListItemClickListener() {
                    /**
                     * @param anchorView 为pop的绑定view
                     * @param anchorViewPosition  pop绑定view在ListView的position
                     * @param index  pop点击item的position 第一个位置索引为0
                     */
                    @Override
                    public void onPopuListItemClick(View anchorView, int anchorViewPosition, int index) {
                        if (index == 0) {
                            conversation.removeMessage(contextMenuMessage.getMsgId());
                            messageList.refresh();
                        } else if (index == 1) {
                            if(contextMenuMessage.getType() == EMMessage.Type.TXT){
                                String string = ((EMTextMessageBody) contextMenuMessage.getBody()).getMessage();
                                clipboard.setText(string);
                            }
                        }
                    }
                }).show();
    }

    @Override
    public void onExtendMenuItemClick(int itemId, View view) {
        switch (itemId) {
            case ITEM_TAKE_PICTURE:
                selectPicFromCamera();
                break;
            case ITEM_PICTURE://ITEM_SHORTCUT:
                selectPicFromLocal(); // 图库选择图片
                break;
        }
    }

    @Override
    public EaseCustomChatRowProvider onSetCustomChatRowProvider() {
        return null;
    }
}
